<template>
	<view class="content">
		<view class="functionBox">
			<u-grid
				:border="true"
				customStyle="margin-top:16px;"
				col="2"
			>
			
				<u-grid-item
					customStyle="padding-top:8px;"
					@click="toGoodList"
					v-if="isLogin"
				>
					<u-icon name="bag" title="商品列表" :size="48" color="#297955"></u-icon>
					<text class="grid-text" >商品列表</text>
				</u-grid-item>
				<u-grid-item
				customStyle="padding-top:8px;"
				v-if="isHasCheckIn"
				@click="jumpToCheckIn"
				>
					<u-icon name="coupon-fill" title="上报库存" :size="48" color="#2979ff"></u-icon>
					<text class="grid-text" >上报库存</text>
				</u-grid-item>
				<u-grid-item 
					v-if="isHasCheckOut"
					customStyle="padding-top:8px;"
					 @click.native="toCheckOut"
				>
					<u-icon name="order" title="出货核销" :size="48"  color="rgb(255,127,39)"></u-icon>
					<text class="grid-text" >出货核销</text>
				</u-grid-item>
				
				<u-grid-item
					customStyle="padding-top:8px;"
					v-if="isHasListMine"
					@click.native="toMyReport"
				>
					<u-icon name="file-text" title="我的上报" :size="48" color="rgb(253,40,67)">
					</u-icon>
					<text class="grid-text" >我的上报</text>
				</u-grid-item>
				
				<u-grid-item
					customStyle="padding-top:8px;"
					v-if="isHasMyCheckOutStatis"
					@click.native="toMyCheckOutStatis"
				>
					<u-icon name="coupon" title="我的统计" :size="48" color="rgb(21,40,67)"></u-icon>
					<text class="grid-text" >我的出货统计</text>
				</u-grid-item>
				
				<u-grid-item
					customStyle="padding-top:8px;"
					v-if="isHasListAll"
					 @click.native="toAllReport"
				>
					<u-icon name="list" title="所有上报" :size="48"  color="rgb(0,128,0)"></u-icon>
					<text class="grid-text"  >所有上报</text>
				</u-grid-item>
				
			</u-grid>
		</view>
		
		<u-empty
		        mode="permission"
		        v-if="hasNoPermisson"
				:textSize="56"
		>
		</u-empty>
	</view>
</template>

<script>
	
	import store from '../../store/store'
	import {readLoginStorage} from '@/api/auth.js'
	export default{
	
		data(){
			return {
				myValue:"",
				isLogin:false,
				model1:{
					name:""
				},
				hasNoPermisson:false,
				isHasCheckIn:false,
				isHasCheckOut:false,
				isHasListMine:false,
				isHasListAll:false,
				isHasMyCheckOutStatis:false
				
			}
		},
		onReady() {
			this.initFuncButtons();
		 },
		methods:{
			initFuncButtons(){
				let wxAuthRes=readLoginStorage();
				if(!wxAuthRes){
					this.hasNoPermisson=true;
					return;
				}
				if(wxAuthRes.token && wxAuthRes.token!=""){
					this.isLogin=true;
				}
				
				let authPrivilDto=wxAuthRes["authPrivilDto"];
				if(authPrivilDto && authPrivilDto.funcCodeList && authPrivilDto.funcCodeList.length>0){
					let funcCodelist=authPrivilDto.funcCodeList;
					if(funcCodelist && funcCodelist.length>0){
						for(let i=0;i<funcCodelist.length;i++){
							let funcCode=funcCodelist[i];
							if(funcCode==="CHECK_IN"){
								this.isHasCheckIn=true;
								continue;
							}
							if(funcCode==="CHECK_OUT"){
								this.isHasCheckOut=true;
							}
							if(funcCode==="MY_REPORT"){
								this.isHasListMine=true;
							}
							if(funcCode==="ALL_REPORT"){
								this.isHasListAll=true;
							}
							if(funcCode==="MY_CHECKOUT_STATIS"){
								this.isHasMyCheckOutStatis=true;
							}
						}
					}
				}
				if(!this.isHasCheckIn && !this.isHasCheckOut && !this.isHasListMine && !this.isHasListAll && !this.isHasMyCheckOutStatis && !this.isLogin){
					this.hasNoPermisson=true;
				}
				
			},
			login(){
				store.commit('invokeTabIndex',-1);
				 uni.reLaunch({
					url:'/pages/index/index'
				}) 
				
				// store.commit('invokeTabIndex',0);
			},
			toGoodList(){
				uni.navigateTo({
					url:'/pages/good/GoodGroupIndex'
				})
			},
			increment(){
				store.commit('increment');
				console.log(store.state.count)
			},
			jumpToCheckIn(){
					uni.navigateTo({
					url:'/pages/checkin/CheckIn'
				});
				
			},
			toMyReport(){
				uni.navigateTo({
					url:'/pages/myreport/MyReportList'
				});
			},
			
			showTet(){
				console.log("showText");
			},
			toAllReport(){
				uni.navigateTo({
					url:'/pages/allreport/AllReport'
				})
			},
			toCheckOut(){
				uni.navigateTo({
					url:'/pages/checkout/CheckOut'
				})
			},
			toMyCheckOutStatis(){
				uni.navigateTo({
					url:'/pages/statis/MyCheckOutStatis'
				})
			}
		},
		
		computed:{
			getCount(){
				return store.getters.getCount;
			},
			getCurrentTabIndex(){
				return store.state.currentTabIndex;
			}
		},
		watch:{
			getCurrentTabIndex(newValue,oldValue){
				console.log("watched change:"+newValue);
			},
			deep:true,
			immediate:true
		}
		
	}
</script>

<style>
	.scroll-view {
	  height:100px;
	}
	.grid-text {
	        font-size: 12px;
	        color: #909399;
	        padding: 10rpx 0 20rpx 0rpx;
	        /* #ifndef APP-PLUS */
	        box-sizing: border-box;
	        /* #endif */
	    }
	.content{
		background-color: rgb(252,252,252);
	}
	.functionBox{
		padding-left: 8px;
		padding-right: 8px;
	}
</style>